
import productRequest from "@/utils/http/productRequest";


export type CategoryListData = CategoryData[]
export interface CategoryData {
    id: number;
    name: string;
    category1Id?: string | number,
    category2Id?: string | number
}


export type AttrValueListData = AttrValueData[]
export interface AttrValueData {
    id?: number | string;
    attrId?: number | string;
    valueName: string;
    isEdit?: boolean
}

export type AttrListData = AttrData[]
export interface AttrData {
    id?: number | string;
    categoryId: number | string;
    categoryLevel: number;
    attrName: string;
    attrValueList: AttrValueListData;
}


export default {
    getCategory1List() {
        return productRequest.get<any, CategoryListData>('/admin/product/getCategory1')
    },
    getCategory2List(category1Id: string) {
        return productRequest.get<any, CategoryListData>(`/admin/product/getCategory2/${category1Id}`)
    },
    getCategory3List(category2Id: string) {
        return productRequest.get<any, CategoryListData>(`/admin/product/getCategory3/${category2Id}`)
    },
    getAttrList(category1Id: string, category2Id: string, category3Id: string) {
        return productRequest.get<any, AttrListData>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
    },
    saveAttr(attr: AttrData) {
        return productRequest.post<any, null>('/admin/product/saveAttrInfo', attr)
    },
    deleteAttr(attrId: string) {
        return productRequest.delete<any, null>(`/admin/product/deleteAttr/${attrId}`)
    }
}

